package scjp.threads.interaction.notifyall;


public class Reader extends Thread {

    Calculator c;

    public Reader(Calculator c) {
        this.c = c;
    }


    @Override
    public void run() {
        synchronized (c) {

            try {
                System.out.println(getName() + " is waiting for calculation...");
                c.wait();

            } catch (InterruptedException ignore) {
            }
            System.out.println(getName() + "..Total is: " + c.total);
        }
    }

    public static void main(String args[]) {

        Calculator calculator = new Calculator();

        new Reader(calculator).start();
        new Reader(calculator).start();
        new Reader(calculator).start();

        calculator.start();

    }

}
